<template>
	<view class="quanbu">
		<view class="neir">
			<view class="iamge">
				<image src="https://hot.guanggaoduo.cn/ad-hot/72_1731046738035.png" mode=""></image>
			</view>
			<view class="shur">
				<view class="jia">
					加盟申请
				</view>
				<view class="yi">
					<view class="bt">
						姓名：
					</view>
					<view class="kuang">
						<input type="text" v-model="quest.name" class="iuput" />
					</view>
				</view>
				<view class="yi">
					<view class="bt">
						联系电话：
					</view>
					<view class="kuang">
						<input type="tel" maxlength="11" v-model="quest.phone" class="iuput" @input="validatePhone" />
						<text v-if="phoneError" class="error">{{ phoneError }}</text>
					</view>
				</view>
				<view class="yi">
					<view class="bt">
						单位名称：
					</view>
					<view class="kuang">
						<input type="text" v-model="quest.compName" class="iuput" />
					</view>
				</view>
			</view>
		</view>
		<view class="jiaojiao" @click="go">
			提交加盟申请
		</view>
	</view>
</template>
<script>
	import {
		joinUs
	} from "@/request/api.js"
	export default {
		data() {
			return {
				quest: {},
				phoneError: ''
			}
		},
		onShow() {},
		methods: {
			validatePhone() {

				const phonePattern = /^1[3-9]\d{9}$/; // 正则表达式：以1开头，第二位为3至9，后面跟9位数字
				if (!this.quest.phone) {
					this.phoneError = '';
				} else if (!phonePattern.test(this.quest.phone)) {
					this.phoneError = '请输入有效的手机号';
				} else {
					this.phoneError = '';
				}
			},
			go() {
				if (!this.quest.name) {
					uni.showToast({
						title: '未填写姓名',
						icon: 'none'
					})
					return
				}
				if (!this.quest.phone) {
					uni.showToast({
						title: '未填写电话',
						icon: 'none'
					})
					return
				}
				joinUs(this.quest).then(res => {
					console.log(res);
					setTimeout(() => {
						uni.navigateBack()
					}, 1500)
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
				})
			},
		},
	}
</script>

<style scoped lang="less">
	.error {
		color: red;
		font-size: 12px;
	}

	.quanbu {
		background: #FAFAFA;
		height: 100vh;
	}

	.neir {
		width: 702rpx;
		margin: 0 auto;
	}

	.iamge {
		width: 702rpx;
		height: 320rpx;
		border-radius: 40rpx;

		image {
			width: 702rpx;
			height: 320rpx;
			border-radius: 40rpx;

		}
	}

	.shur {
		width: 702rpx;
		height: 681rpx;
		background: #FFFFFF;
		border-radius: 20rpx 20rpx 20rpx 20rpx;
		padding: 40rpx 32rpx 50rpx;
		margin-top: 40rpx;
		box-sizing: border-box;

		.jia {

			font-weight: 500;
			font-size: 36rpx;
			color: #333333;
			text-align: center;
			font-style: normal;
			text-transform: none;
			margin-bottom: 20rpx;
		}
	}

	.yi {
		.bt {

			font-weight: 400;
			font-size: 28rpx;
			color: #AAAAAA;

			font-style: normal;
			text-transform: none;
			margin-bottom: 16rpx;
		}

		.kuang {
			.iuput {
				padding-left: 20rpx;
				width: 638rpx;
				height: 96rpx;
				background: #FAFAFA;
				margin-bottom: 40rpx;
				border-radius: 20rpx 20rpx 20rpx 20rpx;
			}
		}
	}

	.jiaojiao {
		margin: 0 auto;
		width: 702rpx;
		height: 88rpx;
		background: #F8492E;
		border-radius: 50rpx 50rpx 50rpx 50rpx;

		font-weight: 500;
		font-size: 32rpx;
		color: #FFFFFF;
		line-height: 88rpx;
		text-align: center;
		font-style: normal;
		text-transform: none;
		margin-top: 200rpx;
	}
</style>